var items=[1,2,3,4,5,6,7,8,9,0,'p','q','r','a','i','x','w','m','h','c']
        function getRandomArrayElements(arr, count) {
            var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
            while (i-- > min) {
                index = Math.floor((i + 1) * Math.random());
                temp = shuffled[index];
                shuffled[index] = shuffled[i];
                shuffled[i] = temp;
            }
            return shuffled.slice(min);
        }
        // 随机颜色
        function randomHexColor() { //随机生成十六进制颜色
            return '#' + ('00000' + (Math.random() * 0x1000000 << 0).toString(16)).substr(-6);
        }
        // 随机倾斜
        function random(min, max){
            return min + Math.floor(Math.random() * (max - min + 1));
        }
        // 随机字体大小
        function randomSize(min, max) {
            return min + Math.floor(Math.random() * (max - min + 1));
        }
        // 集成
        function VerificationCode(Div,num){
            Div.empty();
            var str='';
            $.each(getRandomArrayElements(items, num),function (i,item){
                str+=item
                Div.append("<p style='color: " + randomHexColor() + ";transform:rotate(" + random(-85,85) + "deg);font-size: " + randomSize(16,24) + "px'>" + item + "</p>")
            })
            Div.attr('value',str)

            Div.click(function (){
                VerificationCode(Div,4);
            })
        }
        // 初始加载
    VerificationCode($(".tutu"),4); 
    function strToObj(str){
        if(str){
            return JSON.parse(str)
        }else{
            return {}
        }
    }
// user
var Mobile_Boolean = false;
var yanzheng_Boolean = false;
var duanxin_boolean = false;
var password_Boolean = false;
var varconfirm_Boolean = false;
//手机号
$('.reg_mobile').blur(function(){
if($(".reg_mobile").val()==""){
$('.mobile_hint').html("手机号码不能为空").css("color","red"); 
$('.reg_mobile').css("border","1px solid red"); 
Mobile_Boolean = false; 
    }else if ((/^1[34578]\d{9}$/).test($(".reg_mobile").val())){
      $('.mobile_hint').html("✔").css("color","green");
      $('.reg_mobile').css("border","1px solid #ddd");
      Mobile_Boolean = true;
    }else {
$('.mobile_hint').html("格式输入错误或此号码已被注册").css("color","red");
('.reg_mobile').css("border","1px solid red");  
      Mobile_Boolean = false;
    }
  });
//yanzhengma
$('.x-suiji').blur(function(){
    if($(".x-suiji").val()==""){
    $('.ma1_hint').html("验证码不能为空").css("color","red");
    $('.x-suiji').css("border","1px solid red");
    yanzheng_Boolean = false; 
    }else if($(".x-suiji").val()==$(".suiji").attr('value')){
    $('.ma1_hint').html("✔").css("color","green");
    $('.x-suiji').css("border","1px solid #ddd");
    yanzheng_Boolean = true;
  }else {
    $('.ma1_hint').html("验证码输入错误").css("color","red");
    $('.x-suiji').css("border","1px solid red");
    yanzheng_Boolean = false;
  }
});
// password
$('#password1').blur(function(){
    if($("#password1").val()==""){
    $('.password_hint').html("密码不能为空").css("color","red");
    $('#password1').css("border","1px solid red");
    password_Boolean = false; 
    }else if((/^[0-9a-z@#$%&]{6,18}$/).test($("#password").val())){
    $('.password_hint').html("✔").css("color","green");
    $('#password1').css("border","1px solid #ddd");
    password_Boolean = true;
  }else {
    $('.password_hint').html("密码格式错误").css("color","red");
    $('#password1').css("border","1px solid red");
    password_Boolean = false;
  }
});


// password_confirm
$('#password2').blur(function(){
    if($("#password2").val()==""){
    $('.confirm_hint').html("密码不能为空").css("color","red");
    $('#password2').css("border","1px solid red");
    varconfirm_Boolean = false;
  }else if (($("#password1").val())==($("#password2").val())){
    $('.confirm_hint').html("✔").css("color","green");
    $('#password2').css("border","1px solid #ddd");
    varconfirm_Boolean = true;
  }else {
    $('.confirm_hint').html("两次密码不一致").css("color","red");
    $('#password2').css("border","1px solid red");
    varconfirm_Boolean = false;
  }
});


// click
$('#regg').click(function(){   
 
   var storage=window.localStorage;
  var storage_str=storage.getItem('user')?storage.getItem('user'):'';
    var storage_obj=strToObj(storage_str);

if(yanzheng_Boolean && password_Boolean && varconfirm_Boolean &&  Mobile_Boolean == true){
    alert("注册成功");
   var user= $('.reg_mobile').val();
   var pass= $("#password1").val();
    storage_obj[user]=pass;
    console.log(storage_obj);
    storage.setItem('user',JSON.stringify(storage_obj));
window.location.href = "../../dist/html/login2.html";
  }else {
    alert("请完善信息");
  }
});
